# 16.3 仿真神经网络－－以placeholder传入x值


import tensorflow as tf
import numpy as np

W = tf.Variable(tf.random_normal([3, 2]))
b = tf.Variable(tf.random_normal([1, 2]))

# 第一维设置为None,因为传入的X行数不限，第二维是每一项的数字个数，每一项有3个数字
X = tf.placeholder("float", [None, 3])
y = tf.nn.relu(tf.matmul(X, W) + b)

with tf.Session() as sess:
    init = tf.global_variables_initializer()
    sess.run(init)
    # 第一次使用1X3的数组,后面换成了3X3的数组
    #  X_array = np.array([[0.4, 0.2, 0.4]])
    X_array = np.array([[0.4, 0.2, 0.4]
                           , [0.3, 0.4, 0.5]
                           , [0.3, -0.4, 0.5]])
    # 执行“计算图”时，placeholder X以feed_dict传入X_array
    (_b, _W, _X, _y) = sess.run((b, W, X, y), feed_dict={X: X_array})
    print("b:")
    print(_b)
    print("W:")
    print(_W)
    print("y:")
    print(_y)

    tf.summary.merge_all()
    # 默认写入当前盘的根下，比如：d:/log/area下,可以使用tensorboard --logdir d:/log/area 来查看计算图
    tran_writer = tf.summary.FileWriter('/log/area', sess.graph)

